﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AnguaRPGEngine.Library.Systems;

namespace AnguaRPGEngine.Library.Forms
{
    public partial class PlayerPCEditor : Form
    {

        private List<PlayerPCPair> _PlayerPCs = new List<PlayerPCPair>();
        public List<PlayerPCPair> PlayerPCs
        {
            get
            {
                return _PlayerPCs;
            }
            set
            {
                _PlayerPCs = value;
            }
        }
        public PlayerPCPair PlayerPC
        {
            get
            {
                try
                {
                    return _PlayerPCs.Find(p => p.PlayerCharacterInfo.Name == cboCharacterName.Text && p.PlayerInfo.Name == cboPlayerName.Text);
                }
                catch
                {
                    return null;
                }
            }
            set
            {
                cboPlayerName.Text = value.PlayerInfo.Name;
                cboCharacterName.Text = value.PlayerCharacterInfo.Name;
            }
        }
        public PlayerPCEditor()
        {
            InitializeComponent();
        }
        private void cboPlayerName_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateSavePC();
        }

        private void cboCharacterName_SelectedIndexChanged(object sender, EventArgs e)
        {
            UpdateSavePC();
        }
        private void UpdateSavePC()
        {
            btnSavePlayer.Enabled = (cboCharacterName.SelectedIndex > -1 && cboPlayerName.SelectedIndex > -1);
        }

        private void btnImportPC_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Title = "Open Player Character File";
                ofd.Filter = "Player Character (*.ppc)|*.ppc|Text File (*.txt)|*.txt";
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    PlayerPCPair ppcp = Serializer<PlayerPCPair>.DeserializeFromFile(ofd.FileName);
                    if (ppcp != null)
                    {

                    }
                }
            }
        }

        private void PlayerPCEditor_Load(object sender, EventArgs e)
        {
            UpdateSavePC();
        }
    }
}